package pro.shushi.pamirs.hr.api.model.org;

import pro.shushi.pamirs.boot.base.ux.annotation.field.UxWidget;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxForm;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxTableSearch;
import pro.shushi.pamirs.hr.api.enums.DepartmentTypeEnum;
import pro.shushi.pamirs.meta.annotation.Field;
import pro.shushi.pamirs.meta.annotation.Model;
import pro.shushi.pamirs.meta.base.IdModel;

import java.util.List;

// 模型中UX开头的注解(UxForm/UxTable/UxDetail等)可以不用写，都可在设计器中进行可视化配置; 代码里面写这些注解是为了默认页面的交互
@Model.model(Department.MODEL_MODEL)
@Model(displayName = "标品-部门", labelFields = "name")
// 模型编码，参考：https://doc.oinone.top/oio4/9236.html
@Model.Code(sequence = "SEQ", prefix = "D", size = 5, step = 1, initial = 10000)
public class Department extends IdModel {

    public static final String MODEL_MODEL = "hr.simple.Department";

    @UxTableSearch.FieldWidget(@UxWidget())
    @UxForm.FieldWidget(@UxWidget(readonly = "true", hint = "为空时自动生成"))
    @Field.String
    @Field(displayName = "编码", unique = true)
    private String code;

    @UxTableSearch.FieldWidget(@UxWidget())
    @Field.String
    @Field(displayName = "部门名称", required = true)
    private String name;

    // 可继承的枚举
    @Field(displayName = "部门类型", required = true)
    public DepartmentTypeEnum departmentType;

    @UxTableSearch.FieldWidget(@UxWidget())
    @Field.many2one
    @Field.Relation(relationFields = {"corporationCode"}, referenceFields = {"code"})
    @Field(displayName = "所属公司", required = true)
    private Corporation corporation;

    @Field.String
    @Field(displayName = "所属公司编码", invisible = true)
    private String corporationCode;

    @Field.String
    @Field.Related(related = {"corporation", "shortName"})
    @Field(displayName = "公司名称", invisible = true)
    private String corporationName;

    @Field.many2one
    @Field.Relation(relationFields = {"parentCode"}, referenceFields = {"code"})
    @Field(displayName = "上级部门")
    private Department parent;

    @Field.String
    @Field(displayName = "上级部门编码", invisible = true)
    private String parentCode;

    @Field.Text
    @Field(displayName = "描述")
    private String description;

    // 关系字段参考：https://doc.oinone.top/oio4/9240.html
    @Field.one2many
    @Field.Relation(relationFields = {"code"}, referenceFields = {"departmentCode"})
    @Field(displayName = "岗位列表")
    private List<Position> positions;
}
